import {request} from '../../request/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs:[{
      id:0,
      value:'全部',
      isActive:true
    },{
      id:1,
      value:'销量',
      isActive:false
    },{
      id:2,
      value:'待发货',
      isActive:false
    },{
      id:3,
      value:'退款/退货',
      isActive:false
    },],
    order:[]
  },
  changeIndex(index){
    let {tabs}=this.data;
    tabs.forEach((item,i)=>i===index?item.isActive=true:item.isActive=false)
    this.setData({
      tabs
    })
  },
  tabsChange(e){
    const {index} =e.detail
      this.changeIndex(index)
      this.getOrder(index+1)
  },

onLoad(options){
    const token =wx.getStorageSync('token')
    console.log(token);
 if(!token){
   wx.navigateTo({
     url: '/pages/auth/index',
   })
   return
 }
  const type=options.type
  // console.log(type);
  this.changeIndex(type-1)
  this.getOrder(type)
},
async getOrder(type){
  const {message:res} =await request({url:"my/orders/all",data:{type}})
  console.log(res);
  
  this.setData({
    order:res.orders.map(item=>({...item,create_time:(new Date (item.create_time*1000).toLocaleString())}))
  })
},
   /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
   
  },
})